(ns net.marigolda.test-gui-utils
	(:use clojure.test)
	(:use net.marigolda.gui-utils))

;; wrappers
(deftest test-make-ul
  (is (= "<ul><li>first</li><li>second</li><li>third</li></ul>" (render-snippet (make-ul ["first" "second" "third"])))))

;; formatters
(deftest test-ratio-formatter
  (are [res input] (= res (ratio-formatter input))
        "0.33" (/ 1 3)
        "0.5" (/ 1 2)
        "1.13" (/ 9 8)
        "2" (/ 4 2)))

;; filters
(deftest test-name-autocomplete-filter
  (let [users [{:name "lovely day" :whatever "yes"} {:name "cojure" :whatever "indeed"} {:name "what a laugh" :whatever "no"}]
        list-users '({:as 1, :qs 0, :name "David Grant", :id 40581} {:as 1, :qs 0, :name "Roy", :id 208079} {:as 3, :qs 0, :name "Trey Jackson", :id 6148} {:as 1, :qs 0, :name "Heatsink", :id 499058} {:as 1, :qs 2, :name "user258030", :id 258030})
        noname-users [{:a 1} {:b 2}]]
    (is (= [{:name "lovely day" :whatever "yes"}] (name-autocomplete-filter "da" users)))
    (is (= [] (name-autocomplete-filter "truc" users)))
    (is (= [] (name-autocomplete-filter "truc" noname-users)))
    (is (= '({:as 1, :qs 2, :name "user258030", :id 258030}) (name-autocomplete-filter "us" list-users)))
    (is (= [{:name "lovely day" :whatever "yes"} {:name "what a laugh" :whatever "no"}] (name-autocomplete-filter "l" users)))))